/**
 * 本质上就是要找前驱和后继
 * 用STLset即可
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vll = vector<llt>;

template<typename T>
void input(vector<T>&v, int n){
    v.assign(n + 1, {});
    for(int i=1;i<=n;++i) cin >> v[i];
}

template<typename T>
istream & operator >> (istream & is, vector<T> & v){
    for(auto & i : v) is >> i;
    return is;
}

llt const INF = 0x1F2F3F4F5F6F7F8F;
llt const NINF = -INF;
llt const MOD = 1000000;

int N;
int Tag;
set<int> Set;

void work(){
    llt ans = 0;

	cin >> N;
	Tag = -1;

	for(int t,v,i=1;i<=N;++i){
        cin >> t >> v;
		if(-1 == Tag){
			assert(Set.empty());
			Tag = t;
			Set.insert(v);
		}else if(Tag == t){
			assert(not Set.empty());
			Set.insert(v);
		}else{
			assert(not Set.empty());

			auto p = Set.lower_bound(v);
			if(p == Set.end()){
				--p;
				(ans += v - *p) %= MOD;
				Set.erase(p);
			}else if(p == Set.begin()){
				(ans += *p - v) %= MOD;
				Set.erase(p);
			}else{
				auto c = *p - v;
				--p;
				auto c2 = v - *p;
				if(c2 <= c){
					(ans += c2) %= MOD;
					Set.erase(p);
				}else{
					ans = (ans + c) % MOD;
					Set.erase(++p);
				}				
			}
			if(Set.empty()) Tag = -1;
		}
	}
	cout << ans << endl;
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase; 
    while(nofkase--) work();    
    return 0;
}
